package com.example.yoga.util;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class CodeGenerator {

    private final static String PROJECT_PATH = "D:\\Graduation-project";
    private final static String AUTHOR = "liwenkai";
    private final static String URL = "jdbc:mysql://localhost:3306/yuja?serverTimezone=UTC";
    private final static String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
    private final static String USER_NAME = "root";
    private final static String PASS_WORD = "123";
    private final static String PACKAGE_NAME = "com.example.yoga";
    private final static String TABLE_NAME = "usercombo_status";

    public static void main(String[] args) {
        AutoGenerator autoGenerator = new AutoGenerator();
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir(PROJECT_PATH + "/src/main/java");
        globalConfig.setFileOverride(false);
        globalConfig.setOpen(false);
        globalConfig.setAuthor(AUTHOR);
        globalConfig.setActiveRecord(true);
        globalConfig.setBaseResultMap(true);
        globalConfig.setBaseColumnList(true);
        autoGenerator.setGlobalConfig(globalConfig);

        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL);
        dataSourceConfig.setUrl(URL);
        dataSourceConfig.setDriverName(DRIVER_NAME);
        dataSourceConfig.setUsername(USER_NAME);
        dataSourceConfig.setPassword(PASS_WORD);
        autoGenerator.setDataSource(dataSourceConfig);

        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(true);
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setInclude(TABLE_NAME);
        strategyConfig.setEntityTableFieldAnnotationEnable(true);
        strategyConfig.setLogicDeleteFieldName("is_del");
        autoGenerator.setStrategy(strategyConfig);

        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent(PACKAGE_NAME);
        packageConfig.setXml("mapper");
        packageConfig.setServiceImpl("service");
        autoGenerator.setPackageInfo(packageConfig);

        autoGenerator.execute();
    }
}
